{include file="header.html"}
<body class="gr">

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView">我的收藏</div>
</div>

<div class="favorite-index main-padding-top width-wrap">
	<div class="pullRefresh">
		{if count($data)>0}
		<ul class="list goods-item">
			{foreach from=$data name=g item=g}
			<li>
				<a href="wap.php?app=goods&act=detail&goods_id={$g->id}">
					<div class="pic" style="background-image:url({$g->default_pic});"></div>
					<div class="title"><div>{$g->name}</div><font>{$g->model}</font><span><strong>￥</strong>{number_format($g->price,2)}</span></div>
				</a>
			</li>
			{/foreach}
		</ul>
		{/if}
	</div>
</div>

{include file="footer.html"}
<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li>\
		<a href="wap.php?app=goods&act=detail&goods_id='+g.id+'">\
			<div class="pic" style="background-image:url('+g.default_pic+');"></div>\
			<div class="title"><div>'+g.name+'</div><font>'+g.model+'</font><span><strong>￥</strong>'+g.price.numberFormat(2)+'</span></div>\
		</a>\
	</li>';
	offset++;
	return html;
}
function setLists(){
	var width = ($('.pullRefresh').width()-10*3) / 2;
	$('.list li').width(width);
	$('.list a .pic').loadbackground();
	$('.favorite-index').height($.window().height-$('.favorite-index').padding().top);
}
setLists();
$(window).resize(setLists);
$(function(){
	$('.favorite-index').height($.window().height-$('.favorite-index').padding().top);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=favorite&act=index&type_id=1', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').html(html);
				setLists();
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=favorite&act=index&type_id=1', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').append(html);
				setLists();
				fn();
			});
		}
	});
});
</script>